package com.oim.fx.ui;

import com.oim.fx.ui.component.event.EventAction;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;

/**
 * @author XiaHui
 * @date 2017年8月23日 下午6:03:57
 */
public class RequestFrame extends BaseFrame {

	BorderPane rootPane = new BorderPane();

	HBox topBox = new HBox();
	Label titleLabel = new Label();

	VBox box = new VBox();
	Label label = new Label();

	HBox bottomBox = new HBox();
	Button refuseButton = new Button();
	Button acceptButton = new Button();
	EventAction<?> refuseAction;
	EventAction<?> acceptAction;

	public RequestFrame() {
		initComponent();
		iniEvent();
	}

	private void initComponent() {
		this.setWidth(380);
		this.setHeight(180);
		this.setResizable(false);
		this.setTitlePaneStyle(3);
		this.setRadius(5);
		this.setCenter(rootPane);

		titleLabel.setText("");
		titleLabel.setFont(Font.font("微软雅黑", 14));
		titleLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1)");

		topBox.setStyle("-fx-background-color:#2cb1e0");
		topBox.setPrefHeight(30);
		topBox.setPadding(new Insets(5, 10, 5, 10));
		topBox.setSpacing(10);
		topBox.getChildren().add(titleLabel);

		label.setWrapText(true);
		
		box.setStyle("-fx-background-color:#e8f0f3");
		box.getChildren().add(label);

		refuseButton.setText("拒绝");
		refuseButton.setPrefWidth(80);

		acceptButton.setText("接受");
		acceptButton.setPrefWidth(80);

		bottomBox.setStyle("-fx-background-color:#c9e1e9");
		bottomBox.setAlignment(Pos.BASELINE_RIGHT);
		bottomBox.setPadding(new Insets(5, 10, 5, 10));
		bottomBox.setSpacing(10);
		bottomBox.getChildren().add(refuseButton);
		bottomBox.getChildren().add(acceptButton);

		rootPane.setTop(topBox);
		rootPane.setCenter(box);
		rootPane.setBottom(bottomBox);
	}

	private void iniEvent() {
		this.titleProperty().addListener(l -> {
			titleLabel.setText(getTitle());
		});
	}

//	public void setTitleText(String title) {
//		titleLabel.setText(title);
//	}

	public void setContent(String content) {
		label.setText(content);
	}

	public void setAcceptAction(EventHandler<ActionEvent> value) {
		acceptButton.setOnAction(value);
	}

	public void setRefuseAction(EventHandler<ActionEvent> value) {
		refuseButton.setOnAction(value);
		getTitlePane().addOnCloseAction(value);
	}

	// public void setAcceptAction(EventAction<?> action) {
	// acceptAction = action;
	// }
	//
	// public void setRefuseAction(EventAction<?> action) {
	// refuseAction = action;
	// }
}
